//全局变量存储管理
import Vue from 'vue'
import Vuex from 'vuex'
import Menus from './menu.js';

Vue.use(Vuex);

export default new Vuex.Store({
	state: {
        user: window.localStorage.getItem('user') == null ? '' : JSON.parse(window.localStorage.getItem('user')),
        menu:Menus,
        baseUrl:'http://120.77.209.135:8082',
        // baseUrl:'http://127.0.0.1:8082',
        socket: {
            message: {},
            connected: false,
            reconnectError: false,
            heartBeatTimer: 0,
            heartBeatInterval: 2000,
        }
    },
    getters: {
        curUsername:state=>{
            return state.user.username;
        },
        getBaseUrl:state => {
            return state.baseUrl;
        }
    },
    mutations: {
        login(state,user){
            state.user=user;
            window.localStorage.setItem('user', JSON.stringify(user));
        },
        logout(state){
            window.localStorage.removeItem('user');
            state.user='未登录';
        },
        changeUserAvatar(state,avatar){
            state.user.avatar=avatar;
            window.localStorage.setItem('user', JSON.stringify(state.user));
        },
        changeUserEmail(state,emailInfo){
            state.user.emailActive=emailInfo.emailActive;
            state.user.email=emailInfo.email;
            window.localStorage.setItem('user', JSON.stringify(state.user));
        },
        changeUserPersonalInfo(state,personalInfo){
            state.user.sex=personalInfo.sex;
            state.user.hobby=personalInfo.hobby;
            state.user.mobile=personalInfo.mobile;
            state.user.job=personalInfo.job;
            state.user.age=personalInfo.age;
            state.user.email=personalInfo.email;
            window.localStorage.setItem('user', JSON.stringify(state.user));
        },

    },
    actions: {

    }
});